package com.czxy.service;

import com.czxy.dao.AccountMapper;
import com.czxy.domain.Account;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class AccountServiceImpl implements AccountService{

    @Resource
    private AccountMapper mapper;

    @Override
    public void change(Integer srcId, Integer destId, Double money) {

        // 获取srcId对应的用户 - money
        Account srcAccount = mapper.selectByPrimaryKey(srcId);
        srcAccount.setMoney(srcAccount.getMoney()-money);
        mapper.updateByPrimaryKey(srcAccount);

        // 手动制造异常
        int i = 1/0;


        //获取 destId对应的用户 + money
        Account destAccount = mapper.selectByPrimaryKey(destId);
        destAccount.setMoney(destAccount.getMoney()+money);
        mapper.updateByPrimaryKey(destAccount);


    }
}
